function reloads() {
    document.getElementById("codeImg").src="codeUtil?time=" + new Date();
}
function checkUserName() {
    if($("#loginName").val() == null || $("#loginName").val() === ""){
        $("#userName").text("用户名不能为空！");
        $("#userName").css("color","#ff0000");
        $("#btnSend").attr("disabled",true);
    }else{
        $.ajax({
            type:"POST",
            url:"checkUserNameServlet",
            contentType:"application/json; charset=utf-8",
            data:JSON.stringify({"userName":$("#loginName").val()}),
            dataType:"json",
            complete:function (data) {
                var json = eval("(" + data.responseText + ")");
                if(json.result === "false"){
                    $("#btnSend").attr("disabled",false);
                    $("#userName").text("用户名可以使用！");
                    $("#userName").css("color","#00FF00");
                }else if(json.result === "true"){
                    $("#userName").text("用户名不存在！");
                    $("#btnSend").attr("disabled",true);
                }
            }
        })
    }
}
$("#btnSend").click(function () {
    $.ajax({
        type:"POST",
        url:"loginServlet",
        contentType:"application/json; charset=utf-8",
        data:JSON.stringify(GetJsonData()),
        dataType:"json",
        complete:function (data) {
            var json = eval("("+data.responseText+")");
            if(json.result === "true"){
                window.location.href = json.url;
            }else if(json.result == "false"){
                $("#password").text("密码错误！");
                location.reload();
            }else if(json.code === "false"){
                $("#input_code").text("验证码错误！");
                reloads();
            }
        }
    })
});
$("#btnRegister").click(function () {
    window.location.href = "userRegister.jsp";
});
function GetJsonData() {
    var json = {
        "type":"0",
        "loginName": $("#loginName").val(),
        "pwd": $("#pwd").val(),
        "code":$("#checkCode").val()
    };
    return json;
}